<template>
    <lemon-common uri="class" :sort="sort" ref="commonRef" :search-form-model="searchFormModel" :search-form-item="searchFormItem" :search-condition="searchCondition" :table-item="tableItem" :show-enable="false" :show-unable="false" :dialog-info-form-model="dialogInfoFormModel" :dialog-info-form-item="dialogInfoFormItem" :dialog-edit-form-model="dialogEditFormModel" :dialog-edit-form-item="dialogEditFormItem" :dialog-add-form-model="dialogAddFormModel" :dialog-add-form-item="dialogAddFormItem" @on-add="getSelect" @on-edit="getSelect" @on-info="getSelect"></lemon-common>
</template>

<script setup lang="ts">
import { reactive, inject, ref } from "vue";

//获取自定义全局方法
const { rule, http } = inject<any>("method");

//公共组件ref
const commonRef: any = ref(null);

//排序规则
const sort = reactive({ desc: ["createTime"] });

//年级列表
const gradeOptions = ref<any[]>([]);

//搜索的form
const searchFormModel = reactive({
    name: "",
    houseNum: "",
});

//搜索form子项
const searchFormItem = reactive({
    name: { label: "班级名称", type: "input", clearable: true },
    houseNum: { label: "门牌号", type: "input", clearable: true },
});

//搜索的条件
const searchCondition = reactive({
    name: "like",
    houseNum: "like",
});

//表格每一项
const tableItem = reactive([
    { prop: "name", label: "班级名称", minWidth: "150" },
    { prop: "houseNum", label: "门牌号", minWidth: "150" },
    { prop: "gradeName", label: "所属年级", minWidth: "150" },
    { prop: "createBy", label: "创建人", minWidth: "150" },
    { prop: "createTime", label: "创建时间", minWidth: "200" },
    { prop: "updateBy", label: "修改人", minWidth: "150" },
    { prop: "updateTime", label: "修改时间", minWidth: "200" },
]);

//弹出框详情form
const dialogInfoFormModel = reactive({
    gradeId: null,
    name: "",
    houseNum: "",
    createBy: "",
    createTime: null,
    updateBy: "",
    updateTime: null,
});

//弹出框详情form子项
const dialogInfoFormItem = reactive({
    gradeId: { label: "所属年级", type: "select", options: gradeOptions, readonly: true },
    name: { label: "班级名称", type: "input", readonly: true },
    houseNum: { label: "门牌号", type: "input", readonly: true },
    createBy: { label: "创建人", type: "input", readonly: true },
    createTime: { label: "创建时间", type: "datetime", readonly: true },
    updateBy: { label: "修改人", type: "input", readonly: true },
    updateTime: { label: "修改时间", type: "datetime", readonly: true },
});

//弹出框编辑form
const dialogEditFormModel = reactive({
    id: null,
    gradeId: null,
    name: "",
    houseNum: "",
});

//弹出框编辑form子项
const dialogEditFormItem = reactive({
    gradeId: { label: "所属年级", type: "select", options: gradeOptions, rules: rule.require.select("所属年级") },
    name: { label: "班级名称", type: "input", rules: rule.require.input("班级名称") },
    houseNum: { label: "门牌号", type: "input", rules: rule.require.input("门牌号") },
});

//弹出框添加form
const dialogAddFormModel = reactive({
    gradeId: null,
    name: "",
    houseNum: "",
});

//弹出框添加form子项
const dialogAddFormItem = reactive({
    gradeId: { label: "所属年级", type: "select", options: gradeOptions, rules: rule.require.select("所属年级") },
    name: { label: "班级名称", type: "input", rules: rule.require.input("班级名称") },
    houseNum: { label: "门牌号", type: "input", rules: rule.require.input("门牌号") },
});

//获取年级列表
const getSelect = async () => (gradeOptions.value = await http.get("/class/findGradeSelect"));
</script>

<style scoped lang="less"></style>
